package com.ming.study.elasticsearch.config;

import org.apache.http.HttpHost;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestHighLevelClient;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class SearchClient {

    @Value("${elasticsearch.rest.host}")
    private String hosts;

    @Value("${elasticsearch.rest.port}")
    private String port;

    @Bean
    public RestHighLevelClient buildClient(){
        HttpHost httpHost = new HttpHost(hosts, Integer.parseInt(port), HttpHost.DEFAULT_SCHEME_NAME);
        return new RestHighLevelClient(RestClient.builder(httpHost));
    }
}
